{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4d5e328e",
   "metadata": {},
   "source": [
    "## 1. APP 现货行情-交易规则信息函数总览"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d67e28ac",
   "metadata": {},
   "source": [
    "|方法|解释|\n",
    "|:---|:---|\n",
    "|get_exchangeInfo|以缓存的方式获取一个产品的交易规则与交易对|\n",
    "|get_exchangeInfos|以缓存的方式获取全部产品的交易规则与交易对|\n",
    "|get_symbols_trading_on|获取可以交易的产品列表|\n",
    "|get_symbols_trading_off|获取不可交易的产品列表|\n",
    "|get_symbols_all|获取全部的产品列表|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ecdbbb10",
   "metadata": {},
   "source": [
    "## 2. 模型实例化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "59b56df9",
   "metadata": {},
   "outputs": [],
   "source": [
    "from binance_interface.app import BinanceSPOT\n",
    "from binance_interface.app.utils import eprint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9419b3e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 转发：需搭建转发服务器，可参考：https://github.com/pyted/binance_resender\n",
    "proxy_host = None\n",
    "key = 'xxxx'\n",
    "secret = 'xxxx'\n",
    "\n",
    "binanceSPOT = BinanceSPOT(\n",
    "    key=key, secret=secret,\n",
    "    proxy_host=proxy_host\n",
    ")\n",
    "market = binanceSPOT.market"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "abf75e93",
   "metadata": {},
   "source": [
    "## 3. 以缓存的方式获取一个产品的交易规则与交易对 get_exchangeInfo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0ead0370",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'symbol': 'BTCUSDT',\n",
      "          'status': 'TRADING',\n",
      "          'baseAsset': 'BTC',\n",
      "          'baseAssetPrecision': 8,\n",
      "          'quoteAsset': 'USDT',\n",
      "          'quotePrecision': 8,\n",
      "          'quoteAssetPrecision': 8,\n",
      "          'baseCommissionPrecision': 8,\n",
      "          'quoteCommissionPrecision': 8,\n",
      "          'orderTypes': ['LIMIT', 'LIMIT_MAKER', 'MARKET', 'STOP_LOSS_LIMIT', 'TAKE_PROFIT_LIMIT'],\n",
      "          'icebergAllowed': True,\n",
      "          'ocoAllowed': True,\n",
      "          'quoteOrderQtyMarketAllowed': True,\n",
      "          'allowTrailingStop': True,\n",
      "          'cancelReplaceAllowed': True,\n",
      "          'isSpotTradingAllowed': True,\n",
      "          'isMarginTradingAllowed': True,\n",
      "          'filters': [{'filterType': 'PRICE_FILTER',\n",
      "                       'minPrice': '0.01000000',\n",
      "                       'maxPrice': '1000000.00000000',\n",
      "                       'tickSize': '0.01000000'},\n",
      "                      {'filterType': 'LOT_SIZE',\n",
      "                       'minQty': '0.00001000',\n",
      "                       'maxQty': '9000.00000000',\n",
      "                       'stepSize': '0.00001000'},\n",
      "                      {'filterType': 'ICEBERG_PARTS', 'limit': 10},\n",
      "                      {'filterType': 'MARKET_LOT_SIZE',\n",
      "                       'minQty': '0.00000000',\n",
      "                       'maxQty': '146.15201729',\n",
      "                       'stepSize': '0.00000000'},\n",
      "                      {'filterType': 'TRAILING_DELTA',\n",
      "                       'minTrailingAboveDelta': 10,\n",
      "                       'maxTrailingAboveDelta': 2000,\n",
      "                       'minTrailingBelowDelta': 10,\n",
      "                       'maxTrailingBelowDelta': 2000},\n",
      "                      '......'],\n",
      "          'permissions': ['SPOT', 'MARGIN', 'TRD_GRP_004', 'TRD_GRP_005', 'TRD_GRP_006', '......'],\n",
      "          'defaultSelfTradePreventionMode': 'EXPIRE_MAKER',\n",
      "          'allowedSelfTradePreventionModes': ['EXPIRE_TAKER', 'EXPIRE_MAKER', 'EXPIRE_BOTH'],\n",
      "          'filter': {'PRICE_FILTER': {'filterType': 'PRICE_FILTER',\n",
      "                                      'minPrice': '0.01000000',\n",
      "                                      'maxPrice': '1000000.00000000',\n",
      "                                      'tickSize': '0.01000000'},\n",
      "                     'LOT_SIZE': {'filterType': 'LOT_SIZE',\n",
      "                                  'minQty': '0.00001000',\n",
      "                                  'maxQty': '9000.00000000',\n",
      "                                  'stepSize': '0.00001000'},\n",
      "                     'ICEBERG_PARTS': {'filterType': 'ICEBERG_PARTS', 'limit': 10},\n",
      "                     'MARKET_LOT_SIZE': {'filterType': 'MARKET_LOT_SIZE',\n",
      "                                         'minQty': '0.00000000',\n",
      "                                         'maxQty': '146.15201729',\n",
      "                                         'stepSize': '0.00000000'},\n",
      "                     'TRAILING_DELTA': {'filterType': 'TRAILING_DELTA',\n",
      "                                        'minTrailingAboveDelta': 10,\n",
      "                                        'maxTrailingAboveDelta': 2000,\n",
      "                                        'minTrailingBelowDelta': 10,\n",
      "                                        'maxTrailingBelowDelta': 2000},\n",
      "                     '...': '......'}},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "exchangeInfo_result = market.get_exchangeInfo(symbol='BTCUSDT')\n",
    "eprint(exchangeInfo_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93f9ae4e",
   "metadata": {},
   "source": [
    "## 4. 以缓存的方式获取全部产品的交易规则与交易对 get_exchangeInfos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b59b0161",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': {'timezone': 'UTC',\n",
      "          'serverTime': 1706085110699,\n",
      "          'rateLimits': [{'rateLimitType': 'REQUEST_WEIGHT', 'interval': 'MINUTE', 'intervalNum': 1, 'limit': 6000},\n",
      "                         {'rateLimitType': 'ORDERS', 'interval': 'SECOND', 'intervalNum': 10, 'limit': 100},\n",
      "                         {'rateLimitType': 'ORDERS', 'interval': 'DAY', 'intervalNum': 1, 'limit': 200000},\n",
      "                         {'rateLimitType': 'RAW_REQUESTS', 'interval': 'MINUTE', 'intervalNum': 5, 'limit': 61000}],\n",
      "          'exchangeFilters': [],\n",
      "          'symbols': [{'symbol': 'ETHBTC',\n",
      "                       'status': 'TRADING',\n",
      "                       'baseAsset': 'ETH',\n",
      "                       'baseAssetPrecision': 8,\n",
      "                       'quoteAsset': 'BTC',\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'LTCBTC',\n",
      "                       'status': 'TRADING',\n",
      "                       'baseAsset': 'LTC',\n",
      "                       'baseAssetPrecision': 8,\n",
      "                       'quoteAsset': 'BTC',\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'BNBBTC',\n",
      "                       'status': 'TRADING',\n",
      "                       'baseAsset': 'BNB',\n",
      "                       'baseAssetPrecision': 8,\n",
      "                       'quoteAsset': 'BTC',\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'NEOBTC',\n",
      "                       'status': 'TRADING',\n",
      "                       'baseAsset': 'NEO',\n",
      "                       'baseAssetPrecision': 8,\n",
      "                       'quoteAsset': 'BTC',\n",
      "                       '...': '......'},\n",
      "                      {'symbol': 'QTUMETH',\n",
      "                       'status': 'TRADING',\n",
      "                       'baseAsset': 'QTUM',\n",
      "                       'baseAssetPrecision': 8,\n",
      "                       'quoteAsset': 'ETH',\n",
      "                       '...': '......'},\n",
      "                      '......']},\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "exchangeInfos_result = market.get_exchangeInfos()\n",
    "eprint(exchangeInfos_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cfd91f27",
   "metadata": {},
   "source": [
    "## 5. 获取可以交易的产品列表 get_symbols_trading_on"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d6ff74eb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': ['ETHBTC',\n",
      "          'LTCBTC',\n",
      "          'BNBBTC',\n",
      "          'NEOBTC',\n",
      "          'QTUMETH',\n",
      "          'EOSETH',\n",
      "          'SNTETH',\n",
      "          'BNTETH',\n",
      "          'GASBTC',\n",
      "          'BNBETH',\n",
      "          'BTCUSDT',\n",
      "          'ETHUSDT',\n",
      "          'LRCBTC',\n",
      "          'LRCETH',\n",
      "          'QTUMBTC',\n",
      "          'ZRXBTC',\n",
      "          'KNCBTC',\n",
      "          'FUNETH',\n",
      "          'NEOETH',\n",
      "          'IOTABTC',\n",
      "          'IOTAETH',\n",
      "          'LINKBTC',\n",
      "          'LINKETH',\n",
      "          'XVGETH',\n",
      "          'MTLBTC',\n",
      "          'EOSBTC',\n",
      "          'SNTBTC',\n",
      "          'ETCETH',\n",
      "          'ETCBTC',\n",
      "          'ZECBTC',\n",
      "          '......'],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "symbols_trading_on_result = market.get_symbols_trading_on()\n",
    "eprint(symbols_trading_on_result)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6fe1a5e6",
   "metadata": {},
   "source": [
    "## 6. 获取不可交易的产品列表 get_symbols_trading_off"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6f1cd8b7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': ['BCCBTC',\n",
      "          'HSRBTC',\n",
      "          'OAXETH',\n",
      "          'DNTETH',\n",
      "          'MCOETH',\n",
      "          'ICNETH',\n",
      "          'MCOBTC',\n",
      "          'WTCBTC',\n",
      "          'WTCETH',\n",
      "          'YOYOBTC',\n",
      "          'OMGBTC',\n",
      "          'OMGETH',\n",
      "          'ZRXETH',\n",
      "          'STRATBTC',\n",
      "          'STRATETH',\n",
      "          'SNGLSBTC',\n",
      "          'SNGLSETH',\n",
      "          'BQXBTC',\n",
      "          'BQXETH',\n",
      "          'KNCETH',\n",
      "          'FUNBTC',\n",
      "          'SNMBTC',\n",
      "          'SNMETH',\n",
      "          'XVGBTC',\n",
      "          'SALTBTC',\n",
      "          'SALTETH',\n",
      "          'MDABTC',\n",
      "          'MDAETH',\n",
      "          'MTLETH',\n",
      "          'SUBBTC',\n",
      "          '......'],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "symbols_trading_off_result = market.get_symbols_trading_off()\n",
    "eprint(symbols_trading_off_result) "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a82257a",
   "metadata": {},
   "source": [
    "## 7. 获取全部的产品列表 get_symbols_all"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8691b622",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'code': 200,\n",
      " 'data': ['ETHBTC',\n",
      "          'LTCBTC',\n",
      "          'BNBBTC',\n",
      "          'NEOBTC',\n",
      "          'QTUMETH',\n",
      "          'EOSETH',\n",
      "          'SNTETH',\n",
      "          'BNTETH',\n",
      "          'BCCBTC',\n",
      "          'GASBTC',\n",
      "          'BNBETH',\n",
      "          'BTCUSDT',\n",
      "          'ETHUSDT',\n",
      "          'HSRBTC',\n",
      "          'OAXETH',\n",
      "          'DNTETH',\n",
      "          'MCOETH',\n",
      "          'ICNETH',\n",
      "          'MCOBTC',\n",
      "          'WTCBTC',\n",
      "          'WTCETH',\n",
      "          'LRCBTC',\n",
      "          'LRCETH',\n",
      "          'QTUMBTC',\n",
      "          'YOYOBTC',\n",
      "          'OMGBTC',\n",
      "          'OMGETH',\n",
      "          'ZRXBTC',\n",
      "          'ZRXETH',\n",
      "          'STRATBTC',\n",
      "          '......'],\n",
      " 'msg': ''}\n"
     ]
    }
   ],
   "source": [
    "symbols_all_result = market.get_symbols_all()\n",
    "eprint(symbols_all_result)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
